package com.example.kafka.controller;

import com.example.kafka.service.KafkaAsyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Kafka异步消息发送Controller
 */
@RestController
@RequestMapping("/kafka/async")
public class KafkaAsyncController {

    @Autowired
    private KafkaAsyncService kafkaAsyncService;

    /**
     * 用例1：标准异步发送
     */
    @GetMapping("/standard")
    public String sendStandard() {
        kafkaAsyncService.sendAsyncStandard();
        return "异步发送已触发";
    }

    /**
     * 用例2：异步发送+重试
     */
    @GetMapping("/retry")
    public String sendWithRetry() {
        kafkaAsyncService.sendAsyncWithRetry();
        return "异步发送+重试已触发";
    }

    /**
     * 用例3：异步发送+异常类型细分
     */
    @GetMapping("/error-type")
    public String sendWithErrorType() {
        kafkaAsyncService.sendAsyncWithErrorType();
        return "异步发送+异常类型细分已触发";
    }

    /**
     * 用例4：异步发送+补偿
     */
    @GetMapping("/compensation")
    public String sendWithCompensation() {
        kafkaAsyncService.sendAsyncWithCompensation();
        return "异步发送+补偿已触发";
    }

    /**
     * 用例5：异步发送+最大重试次数与退避
     */
    @GetMapping("/max-retry-backoff")
    public String sendWithMaxRetryAndBackoff() {
        kafkaAsyncService.sendAsyncWithMaxRetryAndBackoff();
        return "异步发送+最大重试次数与退避已触发";
    }
}